<template>
    <div>
        <van-nav-bar title="订单" />
        <van-tabs v-model:active="active" color="#3EB8BC" @click-tab="chooseTab(active)">
            <van-tab :title="item.name" v-for="item in tabs" :key="item.id"></van-tab>
        </van-tabs>
        <div class="main">
            <div class="card" v-for="item, index in orderDate" :key="index">
                <div class="content-top">
                    订单号 <span>20211208013350450</span>
                </div>
                <div class="line"></div>
                <div class="content-middle">
                    <div class="img"><img :src="item.pro_img" alt=""></div>
                    <div class="name">{{ item.pro_title }}</div>
                    <div class="price">
                        ￥{{ item.pro_price }}
                        <p>X{{ item.pro_num }}</p>
                    </div>
                </div>
                <div class="content-bottom">
                    优惠券:￥ 0.00,需付款:<span style="color: red;font-size: 20px;">￥ {{ item.pro_price }}</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import { Token } from '@/utils/request';
interface IOrder {
    orderId: string;
    orderDate: string;
    orderStatus: string;
    orderTotal: number;
    orderDetail: string;
    pro_img: string;
    pro_title: string;
    pro_price: number;
    pro_num: number;
}

interface tabsItem {
    id: number,
    name: string,
    isActive: boolean
}
const orderDate = ref<IOrder[]>([]);
const tabs = ref<tabsItem[]>([])
tabs.value = [
    { id: 0, name: '全部', isActive: true },
    { id: 1, name: '待付款', isActive: false },
    { id: 2, name: '待取件', isActive: false },
    { id: 3, name: '待配送', isActive: false },
    { id: 4, name: '已完成', isActive: false },
]

const getOrder = (active: any) => {
    Token('/api/order', 'get', { status: active }).then((res: any) => {
        orderDate.value = res.data;
        console.log(res.data)
    });

};
getOrder(0)
const active = ref(0);

const chooseTab =async (active: any) => {
    getOrder(active)
}
</script>
<style lang="less" scoped>
body {
    background-color: #F3F4F6;
}

.main {
    width: 94%;
    margin: 20px auto;
}

.card {
    background-color: white;
    border-radius: 20px;
    box-shadow: 0 0 10px #ccc;

    .content-top {
        width: 100%;
        height: 90px;
        padding: 25px;
        font-size: 30px;
        color: #888;
    }

    .content-middle {
        width: 100%;
        height: 250px;
        padding: 20px;
        border-top: 2px solid #ccc;
        border-bottom: 2px solid #ccc;
        display: flex;
        justify-content: space-between;

        .img {
            width: 200px;
            height: 200px;

            img {
                width: 100%;
                height: 100%;
            }
        }

        .name {
            width: 300px;
            font-size: 35px;
        }

        .price {
            color: red;
            font-size: 30px;

            p {
                text-align: end;
                color: #ccc;
                font-size: 25px;
            }
        }
    }

    .content-bottom {
        width: 100%;
        height: 90px;
        padding: 25px;
        font-size: 30px;
        color: #777;
        display: flex;
        align-items: center;
        justify-content: end;
    }
}
</style>